# Code adopted from
# https://stackoverflow.com/questions/65881498/plotly-how-to-round-display-text-in-annotated-heatmap-but-keep-full-format-on-h
# by @vestland
import plotly.express as px
import plotly.figure_factory as ff
import pandas as pd
import plotly
#For saving in HTML
plotly.offline.init_notebook_mode()
#Getting Data
dfc = df.corr()
z = dfc.values.tolist()
z_text = [[str(round(y, 2)) for y in x] for x in z]
#Setting up figure
fig = ff.create_annotated_heatmap(z,
x=list(df.columns),
y=list(df.columns),
zmax=1,
zmin=-1,
annotation_text=z_text,
colorscale='Temps')
#Map's Title
fig.update_layout(title_text='Feature Correlation Map\n',
#xaxis = dict(title='x'),
#yaxis = dict(title='x')
)
#Adding xaxis titles
fig.add_annotation(dict(font=dict(color="black",size=14),
x=0.5,
y=-0.15,
showarrow=False,
text="",
xref="paper",
yref="paper"))
#Adding yaxis titles
fig.add_annotation(dict(font=dict(color="black",size=14),
x=-0.35,
y=0.5,
showarrow=False,
text="",
textangle=-90,
xref="paper",
yref="paper"))
#Centering a map
fig.update_layout(margin=dict(t=75), height=850, width=850)
#Adding a colorbar
fig['data'][0]['showscale'] = True
fig.show()